package com.bole.controller;


import com.bole.dao.CarInfoDao;
import com.bole.dto.car.TbCarDto;
import com.bole.dto.car.TbCarInfoDto;
import com.bole.dto.content.DicContentTypeDto;
import com.bole.pojo.DicContentTypeDo;
import com.bole.pojo.TbCarDo;
import com.bole.pojo.TbCarInFoDo;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("carInfo")
public class CarInFoController {

    @Autowired
    private CarInfoDao carInfoDao;

    @GetMapping("getCarInFoList")
    @ApiOperation(value = "查询全部",notes = "查询全部")
    public List<TbCarInfoDto> getCarInFoList() {
        List<TbCarInFoDo> all = carInfoDao.findAll();
        ArrayList<TbCarInfoDto> carInfoDtos = new ArrayList<>();
        for (TbCarInFoDo carInFoDo : all) {
            TbCarInfoDto carInfoDto = new TbCarInfoDto();
            BeanUtils.copyProperties(carInFoDo, carInfoDto);
            carInfoDtos.add(carInfoDto);
        }
        return carInfoDtos;
    }

    @PostMapping("saveCarInfo")
    @ApiOperation(value = "保存信息",notes = "保存信息")
    @ApiImplicitParam(name = "carInFoDo",value = "分类对象",required = true,dataTypeClass = TbCarInFoDo.class)
    public void saveCarInfo(@RequestBody TbCarInFoDo carInFoDo) {
        TbCarInFoDo save = carInfoDao.save(carInFoDo);
        TbCarInfoDto tbCarInfoDto = new TbCarInfoDto();
        BeanUtils.copyProperties(save, tbCarInfoDto);
    }

    @PostMapping("toUpdate")
    @ApiOperation(value = "车辆信息回显",notes = "车辆信息回显")
    @ApiImplicitParam(name = "id",value = "分类id",required = true,dataTypeClass = Long.class)
    public TbCarInfoDto toUpdate(@RequestParam("id") Long id) {
        TbCarInFoDo carInFoDo = carInfoDao.findById(id).get();
        TbCarInfoDto tbCarInfoDto = new TbCarInfoDto();
        BeanUtils.copyProperties(carInFoDo, tbCarInfoDto);
        return tbCarInfoDto;
    }

    @PostMapping("updateCarInFo")
    @ApiOperation(value = "修改信息",notes = "修改信息")
    @ApiImplicitParam(name = "carInFoDo",value = "分类对象",required = true,dataTypeClass = TbCarInFoDo.class)
    public void updateContentCateInfo(@RequestBody TbCarInFoDo carInFoDo) {
        TbCarInFoDo tbCarInFoDo = carInfoDao.save(carInFoDo);
        TbCarInfoDto tbCarInfoDto = new TbCarInfoDto();
        BeanUtils.copyProperties(tbCarInFoDo, tbCarInfoDto);
    }

    @PostMapping("deleteBatch")
    @ApiOperation(value = "批量删除",notes = "批量删除")
    @ApiImplicitParam(name = "idss",value = "品牌对象",required = true,dataTypeClass = Long.class)
    public void deleteBatch(@RequestParam("idss") List<Long> idss) {
        carInfoDao.deleteBatch(idss);
    }



    @PostMapping("getCarInfoById")
    @ApiOperation(value = "查询")
    @ApiImplicitParam(name = "carId",value = "carId",required = true,dataTypeClass = Long.class)
    public TbCarInfoDto getCarInfoById(@RequestParam("carId") Long carId) {
        TbCarInFoDo carInFoDo  = carInfoDao.findByCarId(carId);
        TbCarInfoDto carInfoDto = new TbCarInfoDto();
        BeanUtils.copyProperties(carInFoDo,carInfoDto);
        return carInfoDto;
    }


}
